"""
@author: xyl
@file: 圣诞节礼物.py
@time: 2022/11/6 19:25
"""
dict = {"A":1, "B":2, "C":3, "D":4, "E":5}
gift = {}
persons = list(dict.keys())
for i in persons:
    flag = 0  # 标记自己带来的礼物是否还未分配出去
    if i in dict:
        flag = 1
        myGift = dict.pop(i)  # 如果自己带来的礼物还未分配，则去掉该礼物
    getGift = dict.popitem()  # 随机返回并移除一对key-value值
    gift[i] = getGift[1]  # 得到的礼物
    if flag:
        dict[i] = myGift  # 将自己的礼物添到未分配礼物中

print(gift)  # 输出礼物分配情况